/*
    Copyright j&g dev team(c). All Rights Reserved
    Notice: Header of IKA-E rendering engine
*/

#ifndef BASE_ENGINE_H
#define BASE_ENGINE_H

#include <SDL/SDL.h>

// WELCOME IKA-E ENGINE!!! //
namespace GoldenAges
{
    class CEngine
    {
    private:
        /** Last iteration's tick value **/
        unsigned long m_lLastTick;

        /** Window width **/
        int m_iWidth;
        /** Window height **/
        int m_iHeight;

        /** Has quit been called? **/
        bool m_bQuit;

        /** The title of the window **/
        const char* m_czTitle;

        /** Screen surface **/
        SDL_Surface* m_pScreen;

        /** Is the window minimized? **/
        bool m_bMinimized;

        /** Variables to calculate the frame rate **/
        /** Tick counter. **/
        int m_iFPSTickCounter;

        /** Frame rate counter. **/
        int m_iFPSCounter;

        /** Stores the last calculated frame rate. **/
        int m_iCurrentFPS;

    protected:
        void DoThink(void);
        void DoRender(void);

        void SetSize(const int& iWidth, const int& iHeight);

        void HandleInput(void);

    public:
        CEngine(unsigned iWidth = 800, unsigned iHeight = 600);
        virtual ~CEngine(void);

        void Init(void);
        void Start(void);

        /** OVERLOADED - Data that should be initialized when the application starts. **/
        virtual void AdditionalInit(void) {}

        /** OVERLOADED - All the games calculation and updating.
            @param iElapsedTime The time in milliseconds elapsed since the function was called last.
        **/
        virtual void Think(const int& iElapsedTime) {}
        /** OVERLOADED - All the games rendering.
            @param pDestSurface The main screen surface.
        **/
        virtual void Render(SDL_Surface* pDestSurf) {}

        /** OVERLOADED - Allocated data that should be cleaned up. **/
        virtual void End(void) {}

        /** OVERLOADED - Window is active again. **/
        virtual void WindowActive(void) {}

        /** OVERLOADED - Window is inactive. **/
        virtual void WindowInactive(void) {}


        /** OVERLOADED - Keyboard key has been released.
            @param iKeyEnum The key number.
        **/
        virtual void KeyUp(const int& iKeyEnum) {}

        /** OVERLOADED - Keyboard key has been pressed.
            @param iKeyEnum The key number.
        **/
        virtual void KeyDown(const int& iKeyEnum) {}


        /** OVERLOADED - The mouse has been moved.
            @param iButton	Specifies if a mouse button is pressed.
            @param iX	The mouse position on the X-axis in pixels.
            @param iY	The mouse position on the Y-axis in pixels.
            @param iRelX	The mouse position on the X-axis relative to the last position, in pixels.
            @param iRelY	The mouse position on the Y-axis relative to the last position, in pixels.

            @bug The iButton variable is always NULL.
        **/
        virtual void MouseMoved(const int& iButton,
                         const int& iX,
                         const int& iY,
                         const int& iRelX,
                         const int& iRelY) {}

        /** OVERLOADED - A mouse button has been released.
            @param iButton	Specifies if a mouse button is pressed.
            @param iX	The mouse position on the X-axis in pixels.
            @param iY	The mouse position on the Y-axis in pixels.
            @param iRelX	The mouse position on the X-axis relative to the last position, in pixels.
            @param iRelY	The mouse position on the Y-axis relative to the last position, in pixels.
        **/

        virtual void MouseButtonUp(const int& iButton,
                        const int& iX,
                         const int& iY,
                         const int& iRelX,
                         const int& iRelY) {}

        /** OVERLOADED - A mouse button has been pressed.
            @param iButton	Specifies if a mouse button is pressed.
            @param iX	The mouse position on the X-axis in pixels.
            @param iY	The mouse position on the Y-axis in pixels.
            @param iRelX	The mouse position on the X-axis relative to the last position, in pixels.
            @param iRelY	The mouse position on the Y-axis relative to the last position, in pixels.
        **/
        virtual void MouseButtonDown(const int& iButton,
                         const int& iX,
                         const int& iY,
                         const int& iRelX,
                         const int& iRelY) {}

        void SetTitle(const char* czTitle);
        const char* GetTitle(void);

        SDL_Surface* GetSurface(void);

        int GetFPS(void);
    };
}

#endif // BASE_ENGINE_H

